//1.
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct commodity
{
	char name[10];
	float price;
};
int PMAX(const struct commodity *p,int n)
{
	float max = p->price;
	int sign = 0;
	register int i = 0;
	for(i = 1; i < n; i++)
	{
		if(max < (p+i)->price)
		{
			max = (p+i)->price;
			sign = i;
		}
	}
	return sign;
}
int main()
{
	struct commodity goods[] = {
					{"保温杯",30.5f},
					{"卫生纸",5.2f},
					{"剃须刀",68.8f}
				   };
	int n = sizeof goods / sizeof goods[0];
	register int i = 0;
	for(; i < n; i++)
	{
		printf("%s%8.1f\n",goods[i].name,goods[i].price);
	}

	struct commodity *q = (struct commodity*)calloc(n,sizeof(struct commodity));
	if(q == NULL)
	{
		puts("内存申请失败");
		return -1;
	}
	memcpy(q,goods,sizeof(struct commodity) * n);
	int sign = PMAX(goods,n);
	int sign2 = PMAX(q,n);
	printf("静态：最高价格的商品为%s,价格为%.1f\n",goods[sign].name,goods[sign].price);
	printf("动态：最高价格的商品为%s,价格为%.1f\n",q[sign2].name,q[sign2].price);
	free(q);
	return 0;

}
